﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace=" System.Collections" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Configuration" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="TarreOA.TarreOAModels" %>
<%@ Import Namespace="TarreOA.TarreOABLL" %>

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            this.DataList_DataTable(0);
        }
    }

    protected void DataList_DataTable(int pcp)
    {
        NetDisktbServices netDiskServices = new NetDisktbServices();
        List<NetDisktb> listCatalogs = netDiskServices.findAll();
        if(listCatalogs != null && listCatalogs.Count > 0)
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            dt.Columns.Add("NetDiskCatalogId", typeof(string));
            dt.Columns.Add("NetDiskCatalogName", typeof(string));
            dt.Columns.Add("NetDiskCatalogPath", typeof(string));
            dt.Columns.Add("Pcps", typeof(string));
            dt.Columns.Add("PcpNames", typeof(string));
            foreach(NetDisktb netDisk in listCatalogs)
            {
                DataRow dr = dt.NewRow();
                dr["NetDiskCatalogId"] = netDisk.NetDiskCatalogId.ToString();
                dr["NetDiskCatalogName"] = netDisk.NetDiskCatalogName;
                if(FindConfigurationPath.instance().NetDiskRoots[netDisk.NetDiskCatalogName] == null)
                {
                    FindConfigurationPath.instance().AddNetDiskRoots(netDisk.NetDiskCatalogName, netDisk.NetDiskCatalogName);
                }
                dr["NetDiskCatalogPath"] = FindConfigurationPath.instance().NetDiskRoots[netDisk.NetDiskCatalogName].ToString();
                dr["Pcps"] = netDisk.Pcps;
                dr["PcpNames"] = netDisk.PcpNames;
                dt.Rows.Add(dr);
            }
            ds.Tables.Add(dt);
            this.DataList1.DataSource = ds.Tables[0].DefaultView;
            this.DataList1.DataBind();
        }
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        User curLoginUser = (User) Session["user"];
        string[] pcps = ((LinkButton) sender).Attributes["pcps"].Trim().Split(',');
        bool state = false;
        for(int i = 0; i < pcps.Length; i++)
        {
            if(pcps[i] != null && !"".Equals(pcps[i]))
            {
                if(pcps[i].Equals("0"))
                {
                    state = true;
                    break;
                }
                else if(curLoginUser.Section.SectionId.ToString().Equals(pcps[i]))
                {
                    state = true;
                }
            }
        }
        if(state)
        {
            string catalogName = ((LinkButton) sender).Text;
            string cid = ((LinkButton) sender).Attributes["nd_id"];
            Response.Redirect("NetDiskCatalogFolderShow.aspx?C_N=" + catalogName + "&C_ID=" + cid);
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('您没有权限访问此目录！');", true);
        }
    }

    protected void DataList1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if(e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            string pcps = ((HtmlInputHidden) e.Item.FindControl("HidNdcOps")).Value;
            string path = ((HtmlInputHidden) e.Item.FindControl("HidNdcPath")).Value;
            string cid = ((HtmlInputHidden) e.Item.FindControl("HidCatalogId")).Value;
            ((LinkButton) e.Item.FindControl("LinkButton1")).Attributes.Add("nd_id", cid);
            ((LinkButton) e.Item.FindControl("LinkButton1")).Attributes.Add("pcps", pcps);
            ((LinkButton) e.Item.FindControl("LinkButton1")).Attributes.Add("dpath", path);
        }
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

                 <link rel="Stylesheet" type="text/css" href="../Styles/right_style.css" />
                <script type="text/javascript" src="../Scripts/jquery.ui/js/jquery.js"></script>

                <style type="text/css">
                <!--
                html{ scrollbar-base-color: #dbecf8; scrollbar-arrow-color: #2a8ed1; scrollbar-track-color: #bdddf2; scrollbar-3dlight-color: #2886c5; scrollbar-darkshadow-color: #2886c5;
                scrollbar-face-color: #dbecf8; scrollbar-shadow-color: #dbecf8;  }
                -->
                </style>


</head>
<body>
    <form id="form1" runat="server">
        <div class="sub_right_top">
  <div class="hdm_header" >
    <div class="tb1_on"><h2 class="h2_icon">网络硬盘</h2></div>

    <div class="clear"></div>
  </div>
  <div class="hdm_footer">
    <div style="height:13px; overflow:hidden;"></div>   
    <asp:Repeater ID="DataList1" runat="server" OnItemDataBound="DataList1_ItemDataBound">
                           <HeaderTemplate>
                                <table width="97%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#77acd0" style="border-collapse:collapse; ">
                                <tr bgcolor="#b1d5ef">
                                <td align="center">共享目录标题</td>
                                <td width="200" align="center">开放范围</td>
                              </tr>
                        </HeaderTemplate>
                        <ItemTemplate>
                                <tr>
                                    <td nowrap="nowrap" style="height: 54px" width="327">
                                        <img border="0" src="../images/disk_share.gif" alt=""/>&nbsp;
                                        <asp:LinkButton ID="LinkButton1" runat="server"
                                            Font-Underline="false" Text='<%# Eval("NetDiskCatalogName") %>'
                                            OnClick="LinkButton1_Click"></asp:LinkButton>
                                        <input id="HidNdcPath" runat="server" type="hidden" value='<%# Eval("NetDiskCatalogPath") %>' />
                                        <input id="HidNdcOps" runat="server" type="hidden" value='<%# Eval("Pcps") %>' />
                                        <input id="HidCatalogId" runat="server" style="width: 95px" type="hidden" value='<%# Eval("NetDiskCatalogId") %>' /></td>
                                    <td align="center" nowrap="nowrap" style="height: 54px">
                                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("PcpNames") %>'
                                            ></asp:Label></td>
                                </tr>
                        </ItemTemplate>
                        <FooterTemplate>
                            </table>
                        </FooterTemplate>
                    </asp:Repeater>
    <div style="height:15px; overflow:hidden;"></div>
  </div>
</div>

    </form>
</body>
</html>
